package com.xzzz.irda.guardcat.server.util;


import com.xzzz.irda.guardcat.server.app.pojo.MachineInfo;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author xzzz
 */
public class MachineTest {

    public static void main(String[] args) {
        MachineInfo m1 = new MachineInfo();
        m1.setProfilesActive("PROD");
        m1.setLastHeartbeatTime(System.currentTimeMillis());

        MachineInfo m2 = new MachineInfo();
        m2.setProfilesActive("DEV");
        m2.setLastHeartbeatTime(System.currentTimeMillis());

        MachineInfo m3 = new MachineInfo();
        m3.setProfilesActive("DAILY");
        m3.setLastHeartbeatTime(System.currentTimeMillis());

        MachineInfo m4 = new MachineInfo();
        m4.setProfilesActive("LOCAL");
        m4.setLastHeartbeatTime(System.currentTimeMillis());

        MachineInfo m5 = new MachineInfo();
        m5.setProfilesActive("PRE");
        m5.setLastHeartbeatTime(System.currentTimeMillis());

        List<MachineInfo> mlist = new ArrayList<>();
        mlist.add(m2);
        mlist.add(m3);
        mlist.add(m4);
        mlist.add(m5);
        mlist.add(m1);


        for (MachineInfo machineInfo : mlist) {
            System.out.println(machineInfo.getProfilesActive());
        }

        System.out.println("===========================");
        List<MachineInfo> newList = mlist.stream().sorted(Comparator.comparingInt(MachineInfo::getSort)).collect(Collectors.toList());

        for (MachineInfo machineInfo : newList) {
            System.out.println(machineInfo.getProfilesActive());
        }

    }
}
